var QTYYSysRoleAdd = function() {
	// 角色增加页面属性开始
	var addAjaxUrl = "/sysRole/add";

	var sysRoleTableId = "sysRoleTable";
	var addSysRoleFormId = "addSysRoleForm";// 增加角色表单id
	var $addSysRoleForm = $("#addSysRoleForm");// 增加角色表单
	var $addSysRoleBtn = $("#addSysRoleBtn");// 增加角色-提交按钮
	var $cancelSysRoleBtn = $("#cancelSysRoleBtn");// 增加角色-取消按钮

	// 授权相关
	var sysFunctionTreeId = "sysFunctionTree";
	var treeAjaxUrl = "sysFunction/list";
	var setting = {
		async : {
			enable : true,
			url : "/sysFunction/list",
			type : "get",
			dataFilter : function(treeId, parentNode, responseData) {
				if (responseData.success == true) {
					responseData = responseData.obj;
					return responseData;
				} else {
					QTYYComponents.bootstrapSweetAlert("", responseData.msg, "error");
				}
			}
		},
		view : {
			showLine : true,
			selectedMulti : true
		},
		data : {
			simpleData : {
				enable : true,
				idKey : "id",
				pidKey : "pId",
				rootPid : 0
			}
		},
		check : {
			enable : true,// 在节点前显示checkbox
			chkboxType : {// 节点级联
				"Y" : "ps",
				"N" : "ps"
			}
		},
		edit : {
			enable : false
		},
		callback : {
			onCheck : function(event, treeId, treeNode) {
				var treeObj = $.fn.zTree.getZTreeObj(treeId);
				var nodes = treeObj.getCheckedNodes(true);
				var idArray = [];
				$.each(nodes, function(i, node) {
					idArray.push(node.id);
				})
				$("input[name='roleFunction']").val(idArray);
			}
		}
	};
	// 角色增加页面属性结束

	/**
	 * 角色增加页面事件绑定
	 */
	var sysRoleAddEventHandler = function() {
		$addSysRoleBtn.on("click", function() {
			$addSysRoleForm.submit();
		});
		$cancelSysRoleBtn.on("click", function() {
			var index = parent.layer.getFrameIndex(window.name); // 先得到当前iframe层的索引
			parent.layer.close(index); // 再执行关闭
		});
	}
	/**
	 * 角色增加页面验证表单
	 */
	var initSysRoleAddBootStrapValidate = function() {
		$addSysRoleForm.bootstrapValidator({
			feedbackIcons : {
				valid : 'glyphicon glyphicon-ok',
				invalid : 'glyphicon glyphicon-remove',
				validating : 'glyphicon glyphicon-refresh'
			},
			fields : {
				sysRoleName : {
					validators : {
						notEmpty : {
							message : '角色名称不能为空'
						}
					}
				}
			}
		}).on("success.form.bv", function(e) {
			QTYYComponentsTable.ajaxFormSumbitTable(addAjaxUrl, addSysRoleFormId, sysRoleTableId);
		});
	}

	var initSysFunctionTree = function(sysFunctionTreeId, setting) {
		QTYYComponentsTree.initTree(sysFunctionTreeId, setting);
	}

	return {
		initSysRoleAdd : function() {
			initSysRoleAddBootStrapValidate();
			sysRoleAddEventHandler();
			initSysFunctionTree(sysFunctionTreeId, setting);
		}
	}
}();
